How to parse strings using elasticsearh












0















I want to use ElasticSearch to separate tokens in a string ,lets say I have a string I want to extract a name from:



John Smith had a little lamb


My idea is to create several versions of it, search them on a name index and get the one with the biggest score:



John
John Smith
John Smith had
....


What's the best way to do that with ElasticSearch?



Edit:
I want something like this:



//this combination is not right, gives me a low score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
],
}
}
}
//this combination is right, gives me a high score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
],
}
}
}
//this one also gives me a low score, stop searching here
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
{ "match" : { "name" : "had" } },
],
}
}
}


How I can do this process in just one query?










share|improve this question

























  • What have you tried so far?

    – common sense
    Nov 20 '18 at 16:56











  • Im running a bool query for each possible sentence, i was wondering if I can do the whole thing on a single query

    – Vitor Souza
    Nov 20 '18 at 18:18











  • Can you include the mapping of your index? Can you include the bool query you tried in your question?

    – Tim
    Nov 20 '18 at 20:53
















0















I want to use ElasticSearch to separate tokens in a string ,lets say I have a string I want to extract a name from:



John Smith had a little lamb


My idea is to create several versions of it, search them on a name index and get the one with the biggest score:



John
John Smith
John Smith had
....


What's the best way to do that with ElasticSearch?



Edit:
I want something like this:



//this combination is not right, gives me a low score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
],
}
}
}
//this combination is right, gives me a high score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
],
}
}
}
//this one also gives me a low score, stop searching here
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
{ "match" : { "name" : "had" } },
],
}
}
}


How I can do this process in just one query?










share|improve this question

























  • What have you tried so far?

    – common sense
    Nov 20 '18 at 16:56











  • Im running a bool query for each possible sentence, i was wondering if I can do the whole thing on a single query

    – Vitor Souza
    Nov 20 '18 at 18:18











  • Can you include the mapping of your index? Can you include the bool query you tried in your question?

    – Tim
    Nov 20 '18 at 20:53














0












0








0








I want to use ElasticSearch to separate tokens in a string ,lets say I have a string I want to extract a name from:



John Smith had a little lamb


My idea is to create several versions of it, search them on a name index and get the one with the biggest score:



John
John Smith
John Smith had
....


What's the best way to do that with ElasticSearch?



Edit:
I want something like this:



//this combination is not right, gives me a low score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
],
}
}
}
//this combination is right, gives me a high score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
],
}
}
}
//this one also gives me a low score, stop searching here
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
{ "match" : { "name" : "had" } },
],
}
}
}


How I can do this process in just one query?










share|improve this question
















I want to use ElasticSearch to separate tokens in a string ,lets say I have a string I want to extract a name from:



John Smith had a little lamb


My idea is to create several versions of it, search them on a name index and get the one with the biggest score:



John
John Smith
John Smith had
....


What's the best way to do that with ElasticSearch?



Edit:
I want something like this:



//this combination is not right, gives me a low score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
],
}
}
}
//this combination is right, gives me a high score
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
],
}
}
}
//this one also gives me a low score, stop searching here
{
"query": {
"bool" : {
"should" : [
{ "match" : { "name" : "John" } },
{ "match" : { "name" : "Smith" } },
{ "match" : { "name" : "had" } },
],
}
}
}


How I can do this process in just one query?







elasticsearch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 16:25







Vitor Souza

















asked Nov 20 '18 at 16:42









Vitor SouzaVitor Souza

11




11













  • What have you tried so far?

    – common sense
    Nov 20 '18 at 16:56











  • Im running a bool query for each possible sentence, i was wondering if I can do the whole thing on a single query

    – Vitor Souza
    Nov 20 '18 at 18:18











  • Can you include the mapping of your index? Can you include the bool query you tried in your question?

    – Tim
    Nov 20 '18 at 20:53



















  • What have you tried so far?

    – common sense
    Nov 20 '18 at 16:56











  • Im running a bool query for each possible sentence, i was wondering if I can do the whole thing on a single query

    – Vitor Souza
    Nov 20 '18 at 18:18











  • Can you include the mapping of your index? Can you include the bool query you tried in your question?

    – Tim
    Nov 20 '18 at 20:53

















What have you tried so far?

– common sense
Nov 20 '18 at 16:56





What have you tried so far?

– common sense
Nov 20 '18 at 16:56













Im running a bool query for each possible sentence, i was wondering if I can do the whole thing on a single query

– Vitor Souza
Nov 20 '18 at 18:18





Im running a bool query for each possible sentence, i was wondering if I can do the whole thing on a single query

– Vitor Souza
Nov 20 '18 at 18:18













Can you include the mapping of your index? Can you include the bool query you tried in your question?

– Tim
Nov 20 '18 at 20:53





Can you include the mapping of your index? Can you include the bool query you tried in your question?

– Tim
Nov 20 '18 at 20:53












1 Answer
1






active

oldest

votes


















0














I am not very clear how you would extract a name from this document. Surely not something elasticsearch can do and will need to come from some logic...
Is the name categorize by words which always start with upper case letter ? If so use whitespace analyzer as english analyzer would lowercase and stem those terms



Regarding score, I'm not clear how this will help you... What score higher is terms which are least common - lamb might be less common in your index than term John or Smith but "little" might be more common, so I don't know how this will help you know that name is "John Smith"
Or are you saying you are looking for set of two tokens/words...



Maybe question here is around clarifying what you want to achieve and then you can check how ES can do it






share|improve this answer
























  • I updated my answer

    – Vitor Souza
    Nov 21 '18 at 16:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397631%2fhow-to-parse-strings-using-elasticsearh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I am not very clear how you would extract a name from this document. Surely not something elasticsearch can do and will need to come from some logic...
Is the name categorize by words which always start with upper case letter ? If so use whitespace analyzer as english analyzer would lowercase and stem those terms



Regarding score, I'm not clear how this will help you... What score higher is terms which are least common - lamb might be less common in your index than term John or Smith but "little" might be more common, so I don't know how this will help you know that name is "John Smith"
Or are you saying you are looking for set of two tokens/words...



Maybe question here is around clarifying what you want to achieve and then you can check how ES can do it






share|improve this answer
























  • I updated my answer

    – Vitor Souza
    Nov 21 '18 at 16:25
















0














I am not very clear how you would extract a name from this document. Surely not something elasticsearch can do and will need to come from some logic...
Is the name categorize by words which always start with upper case letter ? If so use whitespace analyzer as english analyzer would lowercase and stem those terms



Regarding score, I'm not clear how this will help you... What score higher is terms which are least common - lamb might be less common in your index than term John or Smith but "little" might be more common, so I don't know how this will help you know that name is "John Smith"
Or are you saying you are looking for set of two tokens/words...



Maybe question here is around clarifying what you want to achieve and then you can check how ES can do it






share|improve this answer
























  • I updated my answer

    – Vitor Souza
    Nov 21 '18 at 16:25














0












0








0







I am not very clear how you would extract a name from this document. Surely not something elasticsearch can do and will need to come from some logic...
Is the name categorize by words which always start with upper case letter ? If so use whitespace analyzer as english analyzer would lowercase and stem those terms



Regarding score, I'm not clear how this will help you... What score higher is terms which are least common - lamb might be less common in your index than term John or Smith but "little" might be more common, so I don't know how this will help you know that name is "John Smith"
Or are you saying you are looking for set of two tokens/words...



Maybe question here is around clarifying what you want to achieve and then you can check how ES can do it






share|improve this answer













I am not very clear how you would extract a name from this document. Surely not something elasticsearch can do and will need to come from some logic...
Is the name categorize by words which always start with upper case letter ? If so use whitespace analyzer as english analyzer would lowercase and stem those terms



Regarding score, I'm not clear how this will help you... What score higher is terms which are least common - lamb might be less common in your index than term John or Smith but "little" might be more common, so I don't know how this will help you know that name is "John Smith"
Or are you saying you are looking for set of two tokens/words...



Maybe question here is around clarifying what you want to achieve and then you can check how ES can do it







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 21:53









JulienJulien

714




714













  • I updated my answer

    – Vitor Souza
    Nov 21 '18 at 16:25



















  • I updated my answer

    – Vitor Souza
    Nov 21 '18 at 16:25

















I updated my answer

– Vitor Souza
Nov 21 '18 at 16:25





I updated my answer

– Vitor Souza
Nov 21 '18 at 16:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397631%2fhow-to-parse-strings-using-elasticsearh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]