Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 680 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get exact match phrase more than one

#1
Below is the query to get the exact match

GET courses/_search
{
"query": {
"term" : {
"name.keyword": "Anthropology 230"
}
}
}

I need to find the `Anthropology 230` and `Anthropology 250 also`

How to get the exact match
Reply

#2
Assuming you may have more 'Anthropology nnn' items, this should do what you need:

"query":{
"bool":{
"must":[
{"term": {"name.keyword":"Anthropology 230"}},
{"term": {"name.keyword":"Anthropology 250"}},
]
}
}


Reply

#3
You can check and try with, [match][1], [match_phrase][2] or [match_phrase_prefix][3]

Using **match**,

GET courses/_search
{
"query": {
"match" : {
"name" : "Anthropology 230"
}
},
"_source": "name"
}

Using **match_phrase**,

GET courses/_search
{
"query": {
"match_phrase" : {
"name" : "Anthropology"
}
},
"_source": "name"
}

**OR** using [regexp][4],

GET courses/_search
{
"query": {
"regexp" : {
"name" : "Anthropology [0-9]{3}"
}
},
"_source": "name"
}


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

Reply

#4
The mistake that you are doing is that you are using the term query on keyword field and both of them are not analyzed, which means they try to find the exact same search string in inverted index.

What you should be doing is: define a `text` field which you anyway will have if you have not defined your mapping. I am also assuming the same as in your query you mentioned `.keyword` which gets created automatically if you don't define mapping.

Now you can just use below [match query][1] which is analyzed and uses [standard analyzer][2] which splits the token on whitespace, so `Anthropology` `250` and `230` will be generated for your 2 sample docs.

**Simple and efficient query which brings both the docs**

{
"query": {
"match" : {
"name" : "Anthropology 230"
}
}
}

**And search result**

"hits": [
{
"_index": "matchterm",
"_type": "_doc",
"_id": "1",
"_score": 0.8754687,
"_source": {
"name": "Anthropology 230"
}
},
{
"_index": "matchterm",
"_type": "_doc",
"_id": "2",
"_score": 0.18232156,
"_source": {
"name": "Anthropology 250"
}
}
]

The reason why above query matched both docs is that it created two tokens `anthropology` and `230` and matches `anthropology` in both of the documents.

You should definitely read about the [analysis process][3] and can also try [analyze API][4] to see the tokens generated for any text.


**Analyze API output for your text**

POST http://{{hostname}}:{{port}}/{{index-name}}/_analyze

{
"analyzer": "standard",
"text": "Anthropology 250"
}


{
"tokens": [
{
"token": "anthropology",
"start_offset": 0,
"end_offset": 12,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "250",
"start_offset": 13,
"end_offset": 16,
"type": "<NUM>",
"position": 1
}
]
}

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]



Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through